import java.util.*;

public class PolynomialCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入第一个多项式（例如：3x^2+2x-5）：");
        String poly1Str = scanner.nextLine();

        System.out.println("请输入第二个多项式（例如：x^2-4x+6）：");
        String poly2Str = scanner.nextLine();

        System.out.println("请输入运算符（+ - *）：");
        char operator = scanner.next().charAt(0);

        Polynomial poly1 = new Polynomial(poly1Str);
        Polynomial poly2 = new Polynomial(poly2Str);
        Polynomial result = null;

        switch (operator) {
            case '+':
                result = poly1.add(poly2);
                break;
            case '-':
                result = poly1.subtract(poly2);
                break;
            case '*':
                result = poly1.multiply(poly2);
                break;
            default:
                System.out.println("不支持的运算符！");
                System.exit(1);
        }

        System.out.println("运算结果为：" + result);
    }
}